package com.sena.crawler.rundata;

import com.alibaba.fastjson.JSON;
import com.sena.crawler.enums.LinkTypeEnums;
import com.sena.crawler.domian.Link;
import com.sena.crawler.util.JedisUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;

/**
 * @author seven
 * @create 2021-07-29 16:45
 **/
public class RedisRunData extends RunData {

    private static Logger logger = LoggerFactory.getLogger(RedisRunData.class);

    /**
     * 添加到url
     *
     * @param link
     * @return
     */
    @Override
    public boolean addUrl(Link link) {
//        //去重处理
////        if (LinkEnums.ROOT_LINK.getCode().equals(link.getType())) {
////            JedisUtils.setSetValue(LinkTypeEnums.UN_VISITED_URL.getIndex(), LinkTypeEnums.UN_VISITED_URL.getCode(), JSON.toJSONString(link));
////        } else {
////            if (!JedisUtils.hExists(LinkTypeEnums.VISITED_URL.getIndex(), LinkTypeEnums.VISITED_URL.getCode(), link.getLink())) {
////                JedisUtils.setSetValue(LinkTypeEnums.UN_VISITED_URL.getIndex(), LinkTypeEnums.UN_VISITED_URL.getCode(), JSON.toJSONString(link));
////            } else {
////                logger.info(link.getLink(), "已经进行了处理");
////            }
////        }
        return true;
    }

    /**
     * 获取url
     *
     * @return
     */
    @Override
    public Link getUrl() {
//
        return null;

    }


    /**
     * 获取url连接大小
     *
     * @return
     */
    @Override
    public Long getUrlNum() {
//        Jedis jedis = JedisUtils.getInstance();
//        Long size = JedisUtils.getSetSize(LinkTypeEnums.UN_VISITED_URL.getIndex(), LinkTypeEnums.UN_VISITED_URL.getCode());
//        //放在第一个库中 存储普通dbsize
//        return size;
        return null;
    }

    @Override
    public  boolean isFind(Link link){
        return true;
    }
}
